# 树节点定义
class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right

def is_valid_bst(root, min_val=float('-inf'), max_val=float('inf')):
    """验证是否为有效的BST"""
    if not root:
        return True
    if root.val <= min_val or root.val >= max_val:
        return False
    return (is_valid_bst(root.left, min_val, root.val) and 
            is_valid_bst(root.right, root.val, max_val))

def inorder_traversal(root):
    """中序遍历获取节点值"""
    if not root:
        return []
    return inorder_traversal(root.left) + [root.val] + inorder_traversal(root.right)

def test_solution():
    """测试函数"""
    solution = Solution()
    test_cases = generate_test_data()
    
    for i, values in enumerate(test_cases):
        head = create_linked_list(values)
        root = solution.sortedListToBST(head)
        
        # 验证结果
        if not values:
            is_valid = root is None
            result_values = []
        else:
            is_valid = is_valid_bst(root)
            result_values = inorder_traversal(root)
        
        status = "✓" if is_valid and result_values == values else "✗"
        print(f"测试 {i+1}: {status} 输入={values}, BST中序遍历={result_values}")

if __name__ == "__main__":
    test_solution()
